package com.china08.yxyapi.api.home.activity.declaration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.huodong.declaration.YxyHuodongHrbDeclaration;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.declaration.YxyHuodongHrbDeclarationRepository;

@CrossOrigin
@RestController
public class ActivityHrbQualityDeclarationCrtController extends YxyApiBaseController {

    @Autowired
    private YxyHuodongHrbDeclarationRepository yxyHuodongHrbDeclarationRepository;

    @RequestMapping(value = "/api_yw/home/activity/hrb/quality/declaration/crt", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(HttpServletRequest request, HttpServletResponse response,
            @RequestBody(required = false) ReqModel reqModel) {
        String userId = reqModel.userId;
        Integer status = reqModel.status;
        RespModel model = new RespModel();
        YxyHuodongHrbDeclaration findByTeacherIdAndSchoolId = yxyHuodongHrbDeclarationRepository
                .findByTeacherId(userId);
        if (status == 0) {
            findByTeacherIdAndSchoolId.setIsBest(0);
        } else if (status == 1) {
            findByTeacherIdAndSchoolId.setIsBest(1);
        }
        yxyHuodongHrbDeclarationRepository.save(findByTeacherIdAndSchoolId);
        model.setMessage("设置成功");
        return model;
    }

    protected static class ReqModel extends YxyApiPageReqModel {
        // 0 1取消精品 1 设为精品
        public Integer status;
        public String schoolId;
        public String userId;

    }

    protected static class RespModel extends YxyApiRespModel {

    }
}
